package com.onstar.cn.api;

import android.content.Context;

import com.onstar.cn.api.framework.ClazzInjectUtils;
import com.onstar.cn.api.framework.annotation.Path;
import com.onstar.cn.api.framework.annotation.PathParams;
import com.onstar.cn.api.framework.annotation.RequestMapping;
import com.onstar.cn.common.util.DeviceUtil;
import com.onstar.cn.framework.network.entity.RequestEntity;
import com.onstar.cn.mag.enumtype.PackageType;

/**
 * @author Xiaofeng Feng
 * @Title: GprsPackageService.java
 * @date 2015年8月11日 下午2:15:18
 */
@Path("/msp/api/v3/user")
public class GprsPackageService {

    private String serverURL;
    private Context mContext;

    /**
     * @Description: GprsPackageService构造函数
     * @author Xiaofeng Feng
     * @date 2015年9月11日 下午2:01:21
     */

//    public GprsPackageService(String serverURL) {
//        this.serverURL = serverURL;
//    }

    public GprsPackageService(String serverURL, Context context) {
        this.serverURL = serverURL;
        mContext = context;
    }

    /**
     * @Title: getGprsPackageService @Description: 安吉星套餐
     * /subscriber/{subscriberID}/accounts/{accountID}/vehicles/{vin}/packages/my_packages
     * request method:PUT @param 设定文件 @return void
     * 返回类型 @throws
     */
    ///msp/api/v3/user/subscriber/ONSTARM21631143/accounts/1201762298/vehicles/LSGAR5AL2G4240018/packages/my_packages
    @RequestMapping("/subscriber/{subscriberID}/accounts/{accountID}/vehicles/{vin}/packages/my_packages")
    public RequestEntity getGprsPackageService(RequestEntity entity, @PathParams("subscriberID") String subscriberID,
                                               @PathParams("accountID") String accountID, @PathParams("vin") String vin) {
        if (entity == null) {
            entity = new RequestEntity();
        }

        String url = ClazzInjectUtils.injectUrl(getClass(), "getGprsPackageService", entity, subscriberID, accountID, vin);
        entity.setUrl(serverURL + url);
        return entity;
    }

    /**
     * @param @param  entity
     * @param @param  subscriberID
     * @param @param  accountID
     * @param @param  vin
     * @param @return 设定文件
     * @return RequestEntity    返回类型
     * @throws
     * @Title: getPacakagesByVinService
     * @Description: 安吉星套餐列表
     */
    ////msp/api/v3/user/subscriber/00000000000108120310_00000001439776533154_00023/accounts/1201762298/vehicles/LSGAR5AL2G4240018/packages/
    @RequestMapping("/subscriber/{subscriberID}/accounts/{accountID}/vehicles/{vin}/packages")
    public RequestEntity getPacakagesByVinService(RequestEntity entity, @PathParams("subscriberID") String subscriberID,
                                                  @PathParams("accountID") String accountID, @PathParams("vin") String vin, @PathParams("packageType") String packageType) {
        if (entity == null) {
            entity = new RequestEntity();
        }

        String url = ClazzInjectUtils.injectUrl(getClass(), "getPacakagesByVinService", entity, subscriberID, accountID, vin, packageType);
        entity.setUrl(serverURL + url + "?packageType=" + packageType + "&versionCode=" + new DeviceUtil(mContext).getAppVersionCode());
        return entity;
    }

    /**
     * @param @param  entity
     * @param @param  subscriberID
     * @param @param  accountID
     * @param @param  vin
     * @param @return 设定文件
     * @return RequestEntity    返回类型
     * @throws
     * @Title: getCarrierUsageService
     * @Description: 流量套餐
     */
    ///msp/api/v3/user/subscriber/00000000000108059764_00000001430804688959_00013/accounts/1201761430/vehicles/LSGAR55L2F0700527/packages/carrier_usage
    @RequestMapping("/subscriber/{subscriberID}/accounts/{accountID}/vehicles/{vin}/packages/carrier_usage")
    public RequestEntity getCarrierUsageService(RequestEntity entity, @PathParams("subscriberID") String subscriberID,
                                                @PathParams("accountID") String accountID, @PathParams("vin") String vin) {
        if (entity == null) {
            entity = new RequestEntity();
        }

        String url = ClazzInjectUtils.injectUrl(getClass(), "getCarrierUsageService", entity, subscriberID, accountID, vin);
        entity.setUrl(serverURL + url);
        return entity;
    }


    /**
     * @param @param  entity
     * @param @param  subscriberID
     * @param @param  accountID
     * @param @param  vin
     * @param @return 设定文件
     * @return RequestEntity    返回类型
     * @throws
     * @Title: Get order history
     * @Description: 订单历史
     */

  //  /msp/api/v3/user/subscriber/HAPPY001/accounts/1201761200/vehicles/LSGAR5AL2G4240004/packages/order
    @RequestMapping("/subscriber/{idpId}/accounts/{accountID}/vehicles/{vin}/packages/order")
    public RequestEntity getOrderHistory(RequestEntity entity, @PathParams("idpId") String idpId,
                                         @PathParams("accountID") String accountID, @PathParams("vin") String vin,
                                         @PathParams("pageNumber") Integer pageNumber, @PathParams("pageSize") Integer pageSize,
                                         @PathParams("packageType") PackageType packageType) {
        if (entity == null) {
            entity = new RequestEntity();
        }

        String url = ClazzInjectUtils.injectUrl(getClass(), "getOrderHistory", entity, idpId, accountID, vin, pageNumber, pageSize, packageType);
        entity.setUrl(serverURL + url + "?pageNumber=" + (pageNumber <= 0 ? 1 : pageNumber) + "&pageSize="
                + (pageSize <= 0 ? 20 : pageSize) + "&packageType=" + packageType);

        return entity;
    }

    /**
     * @param @param  entity
     * @param @param  subscriberID
     * @param @param  accountID
     * @param @param  vin
     * @param @return 设定文件
     * @return RequestEntity    返回类型
     * @throws
     * @Title: CreateOrder
     * @Description: 创建订单
     */
    ///msp/api/v3/user/subscriber/ONSTARM18554143/accounts/1201761430/vehicles/LSGAR55L2F0700527/packages/2000015/order?packageType=CORE
    @RequestMapping("/subscriber/{subscriberID}/accounts/{accountID}/vehicles/{vin}/packages/{packages}/order")
    public RequestEntity CreateOrder(RequestEntity entity, @PathParams("subscriberID") String subscriberID,
                                     @PathParams("accountID") String accountID, @PathParams("vin") String vin,
                                     @PathParams("packages") String packages, @PathParams("packageType") PackageType packageType) {
        if (entity == null) {
            entity = new RequestEntity();
        }

        String url = ClazzInjectUtils.injectUrl(getClass(), "CreateOrder", entity, subscriberID, accountID, vin, packages, packageType);
        entity.setUrl(serverURL + url + "?packageType=" + packageType);

        return entity;
    }

    /**
     * @param @param  entity
     * @param @param  subscriberID
     * @param @param  accountID
     * @param @param  vin
     * @param @return 设定文件
     * @return RequestEntity    返回类型
     * @throws
     * @Title: GetAlipayWapUrl
     * @Description: 获取网页支付地址
     */
   // /msp/api/v3/user/subscriber/00000000000108059764_00000001430804688959_00013/accounts/1201761430/vehicles/LSGAR55L2F0700527/packages/order/alipay
    @RequestMapping("/subscriber/{subscriberID}/accounts/{accountID}/vehicles/{vin}/packages/order/alipay")
    public RequestEntity GetAlipayWapUrl(RequestEntity entity, @PathParams("subscriberID") String subscriberID,
                                         @PathParams("accountID") String accountID, @PathParams("vin") String vin) {
        if (entity == null) {
            entity = new RequestEntity();
        }

        String url = ClazzInjectUtils.injectUrl(getClass(), "GetAlipayWapUrl", entity, subscriberID, accountID, vin);
        entity.setUrl(serverURL + url);

        return entity;
    }

    /**
     * @param @param  entity
     * @param @param  subscriberID
     * @param @param  accountID
     * @param @param  vin
     * @param @return 设定文件
     * @return RequestEntity    返回类型
     * @throws
     * @Title: GetOrderbyId
     * @Description: 根据订单编号查询订单状态
     */
//    /msp/api/v3/user/subscriber/HAPPY001/accounts/1201761200/vehicles/LSGAR5AL2G4240004/packages/orders/201506290000006025
    @RequestMapping("/subscriber/{subscriberID}/accounts/{accountID}/vehicles/{vin}/packages/orders/{order}")
    public RequestEntity GetOrderbyId(RequestEntity entity, @PathParams("subscriberID") String subscriberID,
                                      @PathParams("accountID") String accountID, @PathParams("vin") String vin, @PathParams("order") String order) {
        if (entity == null) {
            entity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "GetOrderbyId", entity, subscriberID, accountID, vin, order);
        entity.setUrl(serverURL + url);

        return entity;
    }

    /*流量套餐-流量规则*/
    @RequestMapping("/subscriber/{subscriberID}/accounts/{accountID}/vehicles/{vin}/packages/data_rule")
    public RequestEntity getData(RequestEntity entity, @PathParams("subscriberID") String subscriberID,
                                 @PathParams("accountID") String accountID, @PathParams("vin") String vin) {
        if (entity == null) {
            entity = new RequestEntity();
        }
        String url = ClazzInjectUtils.injectUrl(getClass(), "getData", entity, subscriberID, accountID, vin);
        entity.setUrl(serverURL + url + "?versionCode=" + new DeviceUtil(mContext).getAppVersionCode());
        return entity;
    }

}

